﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE.Product.PartData
{
    public partial class Frm_OptionDataAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsOptionDataTable obj = new ClsOptionDataTable();
        ClsPartDataDAO clspartDAO = new ClsPartDataDAO();
        DataTable dt;
        public EventHandler Re_Load;
        public Frm_OptionDataAdd()
        {
            InitializeComponent();
        }

        void ThongBao(string name)
        {
            MessageBox.Show("Chưa nhập " + name + ". Vui lòng nhập lại");
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtAondNote.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.AondNote);
            }
            else if (txtClampTime.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.ClampTime);
            }
            else if (txtMemo.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.Memo);
            }
            else if (txtNote.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.Note);
            }
            else if (txtProTime.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.ProTime);
            }
            else if (txtToolQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBOptionData.FieldName.ToolQty);
            }
            else
            {
                obj.InputDate = dateInputDate.Value;
                obj.PartID = cbPartID.Text;
                obj.MachineID = cbMachineID.Text;
                obj.OptionID = cbOptionID.Text;
                obj.JigID = cbJigID.Text;
                obj.StaffID = cbStaffID.Text;
                obj.ToolQty = int.Parse(txtToolQty.Text);
                obj.ProTime = float.Parse(txtProTime.Text);
                obj.ClampTime = float.Parse(txtClampTime.Text);
                obj.TechDate = checkTechDate.Checked;
                obj.UpdateDay = dateUpdateDay.Value;
                obj.Note = txtNote.Text;
                obj.AondNote = float.Parse(txtAondNote.Text);
                obj.Memo = txtMemo.Text;
                obj.CLUpdateday = dateCLUpdateday.Value;
                obj.LastOption = checkLastOption.Checked;
                
                clspartDAO.InsertOptionData(obj);
                this.Re_Load(sender, e);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Frm_OptionDataAdd_Load(object sender, EventArgs e)
        {
            //lấy PartID
            dt = clspartDAO.GetAllPartID();
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";

            // lấy StaffID
            dt = clspartDAO.GetAllStaffID();
            cbStaffID.DisplayMember = "StaffID";
            cbStaffID.ValueMember = "StaffID";

            // lấy OptionID
            dt = clspartDAO.GetAllOptionID();
            cbOptionID.DisplayMember = "OptionID";
            cbOptionID.ValueMember = "OptionID";

            //
            dt = clspartDAO.GetAllMachineID();
            cbMachineID.DisplayMember = "MachineID";
            cbMachineID.ValueMember = "MachineID";
            
            //Lấy jigID
            dt = clspartDAO.GetAllJigID();
            cbJigID.DisplayMember = "JigID";
            cbJigID.ValueMember = "jigID";
        }
    }
}